<!-- 用户提问文章列表 -->
<template>
  <div>
    <a-list
      item-layout="horizontal"
      :data-source="listData"
      :pagination="pagination"
    >
      <a-list-item slot="renderItem" slot-scope="item">
        <a slot="actions" v-if="!solve && !isOpen" @click="getSolveOpera(item.id)">解决</a>
        <a-list-item-meta :description="'发布时间：' + item.createTime">
          <a slot="title" @click="getDetails(item.id)">{{ item.title }}</a>
        </a-list-item-meta>
      </a-list-item>
    </a-list>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import { getQuestion, editArticle } from "@/apis/article";
export default {
  // import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    // 这里存放数据
    return {
      listData: [],
      isOpen: this.open,
      loading: false,
      solve: this.isSolve,
      pagination: {
        current: 1,
        limit: 5,
        total: 0,
        pageSize: 5,
        hideOnSinglePage: true,
        onChange: (page) => {
          let data = {
            page: page,
            limit: this.pagination.limit,
            userId: this.$route.params.id,
            solve: this.solve,
          };
          this.loading = true;
          getQuestion(data).then((res) => {
            this.listData = res.data.list;
            this.pagination.current = page;
            this.pagination.total = res.data.total;
            this.loading = false;
            $(window).scrollTop(0);
          });
        },
      },
    };
  },
  props: {
    isSolve: {
      type: Boolean
    },
    open: {
      type: Boolean
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {
    isSolve(newValue) {
      this.solve = newValue;
      this.getRouterPageArticle();
    },
    open(newValue) {
      this.isOpen = !newValue;
    },
  },
  //方法集合
  methods: {
    getRouterPageArticle() {
      let data = {
        page: 1,
        limit: 5,
        userId: this.$route.params.id,
        solve: this.solve,
      };
      getQuestion(data).then((res) => {
        this.listData = res.data.list;
        this.pagination.total = res.data.total;
      });
    },
    getDetails(id) {
      this.$router.push("/Details/"+id);
    },
    getSolveOpera(id) {
      let data = {
        id,
        solve: true
      }
      editArticle(data).then(res => {
        this.$message.success(res.msg);
        this.getRouterPageArticle();
      })
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.getRouterPageArticle();
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang="scss" scoped>
//@import url(); 引入公共css类
</style>
